module(..., package.seeall)

--====================================================================--
-- POP UP: MISSION POPUP
--====================================================================--

--[[

******************
 - INFORMATION
******************

  - Monster Popup Info.

--]]

local imgPath = "images/"

new = function (params)
	------------------
	-- Params
	------------------
	local monster_img
	
	local vLabel = "Touch to go back"
	local vReload = false
	--
	local sql = "SELECT ms.*,m.img_320 FROM monster_slot ms INNER JOIN monster m ON m._id=ms.monster_id"..
				" WHERE ms._id="
	--for row in db:nrows("SELECT * FROM monster_slot ms WHERE _id=" .. params.p1) do
	for row in db:nrows( sql .. params.p1) do
		--local text = row._id.." "..row._id
		params.p2 = row.img_320
		print ("popup SLOT_ID is: ", row._id, "  ", row.img_320)
	end
	
	------------------
	-- Groups
	------------------
	
	local localGroup = display.newGroup()
	
	------------------
	-- Display Objects
	------------------
	
	local w, h = display.contentWidth, display.contentHeight
	local background = display.newImage( "background3.png" )
	background.xScale = 1
	background.yScale = 1
	background.alpha = 0.5

		local bdr2 = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
		bdr2:setReferencePoint(display.BottomLeftReferencePoint) 
		bdr2.strokeWidth = 1
		bdr2:setFillColor(255, 100, 100)
		bdr2:setStrokeColor(0, 222, 222)
		bdr2.alpha = 1
		local fncProtection2 = function( event )
			return true
		end	
		bdr2:addEventListener( "tap", fncProtection2 )
	
	--close button
	local btBatsut = function ( event )
		if event.phase == "release" then
			director:closePopUp()
		end
	end

	local btBatsu = ui.newButton{
					default = imgPath .. "cross_yellow_64.png",
					over = imgPath .. "cross_green_64.png",
					onEvent = btBatsut,
					id = "btBatsu"
	}
	btBatsu.x, btBatsu.y = 295,20

	--eo close button
	
	--popup header
	local headerBdr = display.newRect( 10, 0, display.contentWidth-20, 30 )
	headerBdr.strokeWidth = 1
	headerBdr:setFillColor(90, 90, 90)
	headerBdr:setStrokeColor(70, 70, 70)
	
	--popup title
	local popupTitle = display.newText( "MONSTER", 120, 5, native.systemFontBold, 20 )

	--mission contents
	local txtMissionHead = display.newText( "Gozira Power", 120, 50, native.systemFontBold, 19 )
	txtMissionHead:setReferencePoint(display.CenterLeftReferencePoint);
	txtMissionHead.x, txtMissionHead.y = 20, 60
	txtMissionHead:setTextColor( 255,0,0 )
	local txtMissionContent = display.newText( "This is mission one. \nGo to the tower \nand kill some monster!", 120, 50, native.systemFontBold, 16 )
	txtMissionContent:setReferencePoint(display.CenterLeftReferencePoint);
	txtMissionContent.x, txtMissionContent.y = 20, 105
	local txtRewardHead = display.newText( "Reward", 120, 150, native.systemFontBold, 18 )
	txtRewardHead:setReferencePoint(display.CenterLeftReferencePoint);
	txtRewardHead.x, txtRewardHead.y = 20, 200
	txtRewardHead:setTextColor( 255,0,0 )
	local txtRewardContent = display.newText( "Coin 1 \nPotion 2", 120, 50, native.systemFontBold, 16 )
	txtRewardContent:setReferencePoint(display.CenterLeftReferencePoint);
	txtRewardContent.x, txtRewardContent.y = 20, 235
	
	--popup window group
	local headerGroup = display.newGroup();
	headerGroup.x = 0;
	headerGroup.y = 50;
	headerGroup:insert(headerBdr)
	headerGroup:insert(popupTitle)
	headerGroup:insert(txtMissionHead)
	headerGroup:insert(txtMissionContent)
	headerGroup:insert(txtRewardHead)
	headerGroup:insert(txtRewardContent)
	headerGroup:insert(btBatsu)
	headerGroup.xScale = 1;
	headerGroup.yScale = 1;			
	--eo popup window group

	--the monster
	local tirana = display.newImage( imgPath .. params.p2 )
	tirana.xScale = 0.8
	tirana.yScale = 0.8
	tirana.x = display.contentWidth/2
	tirana.y = display.contentHeight/2
	--tirana.rotation = -70
	--tirana.xScale = -0.4
	

	
	
	
	------------------
	-- Listeners
	------------------
	
	local touched = function ( event )
		if event.phase == "ended" then
			director:closePopUp()
		end
	end
	
	local closed = function ( event )
		if event.phase == "ended" then
			director:closePopUp()
		end
	end
	

	
	--====================================================================--
	-- INITIALIZE
	--====================================================================--
	
	local function initVars ()
		
		------------------
		-- Inserts
		------------------
		
		localGroup:insert( background )
		localGroup:insert( headerGroup )
		localGroup:insert( bdr2 )
		localGroup:insert( btBatsu )
		localGroup:insert( tirana )
		
		
		------------------
		-- Positions
		------------------
		
		--
		
		------------------
		-- Colors
		------------------
		
		--title:setTextColor( 255,255,255 )
		
		------------------
		-- Listeners
		------------------
		
		--background:addEventListener( "touch" , touched )
		
	end
	
	------------------
	-- Initiate variables
	------------------
	
	initVars()
	
	------------------
	-- MUST return a display.newGroup()
	------------------
	
	return localGroup
	
end
